/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.news;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import myUtils.page.Page;
import myUtils.page.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.News;
import po.User;
import service.UserService;

/**
 *
 * @author sony
 */
public class MyNewsListAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request;
    private UserService userService;

    @Override
    public String execute() {
        if (ActionContext.getContext().getSession().get("user") == null) {
            return ERROR;
        } else {
            int userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
            Result result = userService.getMyNews(userId, request.getParameter("page") == null ? 1 : Integer.parseInt((String) request.getParameter("page")));
            request.setAttribute("result", result);
            return SUCCESS;
        }
    }

    public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
}
